{"ast":null,"code":"import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport { useState, useRef } from 'react';\nimport raf from \"rc-util/es/raf\";\nimport { getClientSize } from \"rc-util/es/Dom/css\";\nimport { MIN_SCALE, MAX_SCALE } from \"../previewConfig\";\nvar initialTransform = {\n  x: 0,\n  y: 0,\n  rotate: 0,\n  scale: 1\n};\nexport default function useImageTransform(imgRef) {\n  var frame = useRef(null);\n  var queue = useRef([]);\n  var _useState = useState(initialTransform),\n    _useState2 = _slicedToArray(_useState, 2),\n    transform = _useState2[0],\n    setTransform = _useState2[1];\n  var resetTransform = function resetTransform() {\n    setTransform(initialTransform);\n  };\n  /** Direct update transform */\n\n  var updateTransform = function updateTransform(newTransform) {\n    if (frame.current === null) {\n      queue.current = [];\n      frame.current = raf(function () {\n        setTransform(function (preState) {\n          var memoState = preState;\n          queue.current.forEach(function (queueState) {\n            memoState = _objectSpread(_objectSpread({}, memoState), queueState);\n          });\n          frame.current = null;\n          return memoState;\n        });\n      });\n    }\n    queue.current.push(_objectSpread(_objectSpread({}, transform), newTransform));\n  };\n  /** Scale according to the position of clientX and clientY */\n\n  var dispatchZoonChange = function dispatchZoonChange(ratio, clientX, clientY) {\n    var _imgRef$current = imgRef.current,\n      width = _imgRef$current.width,\n      height = _imgRef$current.height,\n      offsetWidth = _imgRef$current.offsetWidth,\n      offsetHeight = _imgRef$current.offsetHeight,\n      offsetLeft = _imgRef$current.offsetLeft,\n      offsetTop = _imgRef$current.offsetTop;\n    var newRatio = ratio;\n    var newScale = transform.scale * ratio;\n    if (newScale > MAX_SCALE) {\n      newRatio = MAX_SCALE / transform.scale;\n      newScale = MAX_SCALE;\n    } else if (newScale < MIN_SCALE) {\n      newRatio = MIN_SCALE / transform.scale;\n      newScale = MIN_SCALE;\n    }\n    /** Default center point scaling */\n\n    var mergedClientX = clientX !== null && clientX !== void 0 ? clientX : innerWidth / 2;\n    var mergedClientY = clientY !== null && clientY !== void 0 ? clientY : innerHeight / 2;\n    var diffRatio = newRatio - 1;\n    /** Deviation calculated from image size */\n\n    var diffImgX = diffRatio * width * 0.5;\n    var diffImgY = diffRatio * height * 0.5;\n    /** The difference between the click position and the edge of the document */\n\n    var diffOffsetLeft = diffRatio * (mergedClientX - transform.x - offsetLeft);\n    var diffOffsetTop = diffRatio * (mergedClientY - transform.y - offsetTop);\n    /** Final positioning */\n\n    var newX = transform.x - (diffOffsetLeft - diffImgX);\n    var newY = transform.y - (diffOffsetTop - diffImgY);\n    /**\n     * When zooming the image\n     * When the image size is smaller than the width and height of the window, the position is initialized\n     */\n\n    if (ratio < 1 && newScale === 1) {\n      var mergedWidth = offsetWidth * newScale;\n      var mergedHeight = offsetHeight * newScale;\n      var _getClientSize = getClientSize(),\n        clientWidth = _getClientSize.width,\n        clientHeight = _getClientSize.height;\n      if (mergedWidth <= clientWidth && mergedHeight <= clientHeight) {\n        newX = 0;\n        newY = 0;\n      }\n    }\n    updateTransform({\n      x: newX,\n      y: newY,\n      scale: newScale\n    });\n  };\n  return {\n    transform: transform,\n    resetTransform: resetTransform,\n    updateTransform: updateTransform,\n    dispatchZoonChange: dispatchZoonChange\n  };\n}\n;","map":{"version":3,"names":["_objectSpread","_slicedToArray","useState","useRef","raf","getClientSize","MIN_SCALE","MAX_SCALE","initialTransform","x","y","rotate","scale","useImageTransform","imgRef","frame","queue","_useState","_useState2","transform","setTransform","resetTransform","updateTransform","newTransform","current","preState","memoState","forEach","queueState","push","dispatchZoonChange","ratio","clientX","clientY","_imgRef$current","width","height","offsetWidth","offsetHeight","offsetLeft","offsetTop","newRatio","newScale","mergedClientX","innerWidth","mergedClientY","innerHeight","diffRatio","diffImgX","diffImgY","diffOffsetLeft","diffOffsetTop","newX","newY","mergedWidth","mergedHeight","_getClientSize","clientWidth","clientHeight"],"sources":["/data/messenger.client/node_modules/rc-image/es/hooks/useImageTransform.js"],"sourcesContent":["import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport { useState, useRef } from 'react';\nimport raf from \"rc-util/es/raf\";\nimport { getClientSize } from \"rc-util/es/Dom/css\";\nimport { MIN_SCALE, MAX_SCALE } from \"../previewConfig\";\nvar initialTransform = {\n  x: 0,\n  y: 0,\n  rotate: 0,\n  scale: 1\n};\nexport default function useImageTransform(imgRef) {\n  var frame = useRef(null);\n  var queue = useRef([]);\n\n  var _useState = useState(initialTransform),\n      _useState2 = _slicedToArray(_useState, 2),\n      transform = _useState2[0],\n      setTransform = _useState2[1];\n\n  var resetTransform = function resetTransform() {\n    setTransform(initialTransform);\n  };\n  /** Direct update transform */\n\n\n  var updateTransform = function updateTransform(newTransform) {\n    if (frame.current === null) {\n      queue.current = [];\n      frame.current = raf(function () {\n        setTransform(function (preState) {\n          var memoState = preState;\n          queue.current.forEach(function (queueState) {\n            memoState = _objectSpread(_objectSpread({}, memoState), queueState);\n          });\n          frame.current = null;\n          return memoState;\n        });\n      });\n    }\n\n    queue.current.push(_objectSpread(_objectSpread({}, transform), newTransform));\n  };\n  /** Scale according to the position of clientX and clientY */\n\n\n  var dispatchZoonChange = function dispatchZoonChange(ratio, clientX, clientY) {\n    var _imgRef$current = imgRef.current,\n        width = _imgRef$current.width,\n        height = _imgRef$current.height,\n        offsetWidth = _imgRef$current.offsetWidth,\n        offsetHeight = _imgRef$current.offsetHeight,\n        offsetLeft = _imgRef$current.offsetLeft,\n        offsetTop = _imgRef$current.offsetTop;\n    var newRatio = ratio;\n    var newScale = transform.scale * ratio;\n\n    if (newScale > MAX_SCALE) {\n      newRatio = MAX_SCALE / transform.scale;\n      newScale = MAX_SCALE;\n    } else if (newScale < MIN_SCALE) {\n      newRatio = MIN_SCALE / transform.scale;\n      newScale = MIN_SCALE;\n    }\n    /** Default center point scaling */\n\n\n    var mergedClientX = clientX !== null && clientX !== void 0 ? clientX : innerWidth / 2;\n    var mergedClientY = clientY !== null && clientY !== void 0 ? clientY : innerHeight / 2;\n    var diffRatio = newRatio - 1;\n    /** Deviation calculated from image size */\n\n    var diffImgX = diffRatio * width * 0.5;\n    var diffImgY = diffRatio * height * 0.5;\n    /** The difference between the click position and the edge of the document */\n\n    var diffOffsetLeft = diffRatio * (mergedClientX - transform.x - offsetLeft);\n    var diffOffsetTop = diffRatio * (mergedClientY - transform.y - offsetTop);\n    /** Final positioning */\n\n    var newX = transform.x - (diffOffsetLeft - diffImgX);\n    var newY = transform.y - (diffOffsetTop - diffImgY);\n    /**\n     * When zooming the image\n     * When the image size is smaller than the width and height of the window, the position is initialized\n     */\n\n    if (ratio < 1 && newScale === 1) {\n      var mergedWidth = offsetWidth * newScale;\n      var mergedHeight = offsetHeight * newScale;\n\n      var _getClientSize = getClientSize(),\n          clientWidth = _getClientSize.width,\n          clientHeight = _getClientSize.height;\n\n      if (mergedWidth <= clientWidth && mergedHeight <= clientHeight) {\n        newX = 0;\n        newY = 0;\n      }\n    }\n\n    updateTransform({\n      x: newX,\n      y: newY,\n      scale: newScale\n    });\n  };\n\n  return {\n    transform: transform,\n    resetTransform: resetTransform,\n    updateTransform: updateTransform,\n    dispatchZoonChange: dispatchZoonChange\n  };\n}\n;"],"mappings":"AAAA,OAAOA,aAAa,MAAM,0CAA0C;AACpE,OAAOC,cAAc,MAAM,0CAA0C;AACrE,SAASC,QAAQ,EAAEC,MAAM,QAAQ,OAAO;AACxC,OAAOC,GAAG,MAAM,gBAAgB;AAChC,SAASC,aAAa,QAAQ,oBAAoB;AAClD,SAASC,SAAS,EAAEC,SAAS,QAAQ,kBAAkB;AACvD,IAAIC,gBAAgB,GAAG;EACrBC,CAAC,EAAE,CAAC;EACJC,CAAC,EAAE,CAAC;EACJC,MAAM,EAAE,CAAC;EACTC,KAAK,EAAE;AACT,CAAC;AACD,eAAe,SAASC,iBAAiB,CAACC,MAAM,EAAE;EAChD,IAAIC,KAAK,GAAGZ,MAAM,CAAC,IAAI,CAAC;EACxB,IAAIa,KAAK,G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